home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / MIDI / MidiChaos_15 Folder / MidiChaos_1.5 / Source / Voice < prev   
Text File  |  1995-04-28  |  2KB  |  118 lines

  1. \ This class uses chaotic_critters to generate and play midi information.
  2. \
  3. \ Author: Darren Gibbs  Copyright 1990
  4. \ Date:   10/3/90
  5.  
  6. ANEW TASK-VOICE
  7.  
  8. OB.OBJLIST VOICE-LIST
  9. TEXTROM VOICE-NAMES ," VOICE-1 " ," VOICE-2 " ," VOICE-3" ," VOICE-4"
  10.  
  11. 3 CONSTANT #PARAMS
  12.   0 CONSTANT NOTE
  13.   1 CONSTANT VELOCITY
  14.   2 CONSTANT DURATION
  15.  
  16. TEXTROM PARAMETER-NAMES  ," Note" ," Velocity" ," Duration"
  17. : GET.#PARAMS  ( -- n )
  18.     #params
  19. ;
  20.  
  21. : GET.PARAMETER.NAME  ( index -- $string )
  22.     parameter-names uncount.text
  23. ;
  24.  
  25. METHOD GENERATOR@:  
  26.  
  27. :CLASS OB.VOICE  <SUPER OB.JOB    
  28.     OB.MIDI.INSTRUMENT IO-INSTRUMENT
  29.     OB.CHAOTIC_CRITTER IO-NOTE-CRITTER
  30.     OB.CHAOTIC_CRITTER IO-VELOCITY-CRITTER
  31.     OB.CHAOTIC_CRITTER IO-DURATION-CRITTER
  32.     
  33. :M GENERATOR@: ( index -- critter_addr )
  34.     CASE
  35.         0 OF io-note-critter      ENDOF
  36.         1 OF io-velocity-critter ENDOF
  37.         2 OF io-duration-critter ENDOF
  38.     ENDCASE
  39. ;M
  40.  
  41. :M PUT.CHANNEL: ( chan# -- )
  42.     put.channel: io-instrument
  43. ;M
  44.  
  45. :M GET.CHANNEL: ( -- chan# )
  46.     get.channel: io-instrument
  47. ;M
  48.  
  49. :M PRINT:  ( -- )  
  50.     cr name: self cr
  51.     ." Channel#: " get.channel: io-instrument . cr
  52. ;M    
  53.     
  54. : VOICE.FUNCTION  ( job_addr -- calculate data and play note )
  55.     exec: io-note-critter
  56.     exec: io-velocity-critter
  57.     exec: io-duration-critter
  58.     dup>r \ keep copy of duration
  59.     time@ vtime!  
  60.     note.on.for: io-instrument
  61.     r> swap  put.duration: []
  62. ;
  63.     
  64. :M NEW:  ( 1 -- )
  65.     new: super
  66.     'c voice.function add: self
  67.  
  68. \    " NOTE-GENERATOR "      put.name: io-note-critter
  69. \    " VELOCITY-GENERATOR "  put.name: io-velocity-critter
  70. \    " DURATION-GENERATOR "  put.name: io-duration-critter
  71.  
  72.     io-instrument put.instrument: self
  73.     0 put.offset: io-instrument
  74.     1 put.channel: io-instrument
  75. ;M
  76.  
  77.  
  78. ;CLASS
  79.  
  80. : MAKE.VOICES  ( n -- , instantiate voices and add to list )
  81.     dup new: voice-list
  82.     0 DO
  83.         instantiate ob.voice 
  84.         1 over new: []
  85.         add: voice-list
  86.     LOOP
  87. ;
  88.  
  89. : FREE.VOICES  ( -- )
  90.     many: voice-list 0 
  91.     DO
  92.         I at: voice-list  dup
  93.         free: []  
  94.         deinstantiate
  95.     LOOP
  96.     free: voice-list
  97. ;
  98.  
  99. : PAUSE.VOICES  ( -- )
  100.     many: voice-list 0
  101.     DO
  102.         I at: voice-list dup  ?executing: []
  103.         IF -1 over put.data: []  stop: []
  104.         ELSE drop
  105.         THEN
  106.     LOOP
  107. ;
  108.  
  109. : UNPAUSE.VOICES  ( -- )
  110.     many: voice-list 0
  111.     DO
  112.         I at: voice-list dup  get.data: []
  113.         IF 0 over put.data: [] start: []
  114.         ELSE drop
  115.         THEN
  116.     LOOP
  117. ;
  118.